package com.ycc.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;

public class PrincipalUtil {
    private static final ObjectMapper mapper = new ObjectMapper();

    public static String getSubFromPrincipal(Object principal) {
        Map principalMap = mapper.convertValue(principal, Map.class);
        return (String) principalMap.get("sub");
    }

    public static Integer getUserIdFromPrincipal(Object principal) {
        Map principalMap = mapper.convertValue(principal, Map.class);
        return (Integer) principalMap.get("userId");
    }
}